﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using GtsServer.Common;

namespace GtsServer.DAL
{
    public partial class OrderSZFDetailDAL
    {
        public OrderSZFDetailDAL() { }

        public DataSet GetList(int pageIndex, int pageSize, string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from ( select oszf.ID, pt.Name,od.OrderAccount,t.Name TaskName,u.IMSI,oszf.CardNum,oszf.CardPwd,od.Price,oszf.SzfPrice,case oszf.Op when '1' then '中国移动' when '2' then '中国联通' when '3' then '中国电信' end OpName, '160629' MerNum,od.CreateTime,od.PayTime,case od.State when '1' then '支付成功' when '0' then '未支付' end StateName,ROW_NUMBER() OVER(order by od.CreateTime desc) as RowNumber ");
            strSql.Append(" from OrderSZFDetail oszf left join [Order] od on oszf.OrderID=od.ID left join OrderDetail odt on odt.OrderID=od.ID left join Task t on t.ID =odt.TaskID left join Prize pr on od.PrizeID=pr.ID left join PrizeType pt on pr.PrizeTypeID=pt.ID left join [user] u on od.UserID=u.ID ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" ) a where  RowNumber BETWEEN " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize + ";");
            strSql.Append(" select COUNT(1) from OrderSZFDetail oszf left join [Order] od on oszf.OrderID=od.ID left join Prize pr on od.PrizeID=pr.ID left join OrderDetail odt on odt.OrderID=od.ID left join PrizeType pt on pr.PrizeTypeID=pt.ID left join [user] u on od.UserID=u.ID ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
    }
}
